Repository navigation
Conversation
Slot refresh can evict a cached EVP_PKEY while a caller's RSA key still owns the backing PKCS#11 object. Signing used to look up the freed wrapper just to obtain the RSA size. Use the RSA key already supplied by OpenSSL instead. Keep fast repeated key loads by pinning the cached wrapper during lookup and detaching it on eviction. Prevent detached objects from recreating the reference cycle, and release the cache lock in both processes after a fork. Fixes OpenSC#694
Legacy ECDSA and ECDH methods lack the finish hook that releases the backing PKCS#11 object on newer OpenSSL versions. The leaked reference keeps the object and its slot alive after cache eviction. Attach the lifetime callbacks to the EC_KEY on OpenSSL 1.0.2. Each copy takes its own reference, and freeing the key releases it without leaving callbacks registered globally after libp11 is unloaded.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request Type
Related Issue
Fixes #694
Current Behavior
Refreshing slots can free the cached
EVP_PKEYwhile a caller still holds a usable RSA key. The next signature can crash when it reads the freed wrapper to determine the RSA size.New Behavior
RSA signing uses the key OpenSSL already passed in. Retained keys continue to sign after a slot refresh when the token remains available, and repeated key loads still benefit from the cache.
Scope of Changes
Synchronize cache lookup and eviction without holding the cache lock during token operations. Preserve separate wrappers for callers and prevent the cache lock from being inherited locked at fork. A separate commit pairs legacy EC key references with cleanup callbacks on OpenSSL 1.0.2.
Testing
make check(49 passed, 5 skipped).Additional Notes
Stale PKCS#11 handles after logout or session loss remain tracked in #696.
License Declaration